package com.westar.tv;

import android.os.Bundle;
import android.support.annotation.StringRes;
import android.support.v7.app.AppCompatActivity;
import android.view.WindowManager;
import android.widget.Toast;

/**
 * Created by wang-dev
 */
public abstract class BaseActivity extends AppCompatActivity {

    //日志tag
    protected String tag;

    //app实例
    protected CustomApplication app;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //日志tag
        tag = this.getClass().getSimpleName();
        //application
        app = (CustomApplication) this.getApplication();
        //添加Activity到堆栈
        app.addActivity(this);
        //防止页面休眠
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    }

    @Override
    protected void onStart() {
        super.onStart();
    }


    @Override
    protected void onStop() {
        super.onStop();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        //结束Activity&从栈中移除该Activity
        app.finishActivity(this);
    }

    /**
     * 显示Toast
     *
     * @param msg
     */
    protected void showShortToast(@StringRes int msg) {
        Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
    }

    /**
     * 显示Toast
     *
     * @param msg
     */
    protected void showShortToast(String msg) {
        Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
    }

}
